Skip to content

Add extract to download_dataset and download_sample - #155

Merged
Kostis-S-Z merged 9 commits into
mainfrom
download-extract
Oct 19, 2026
Merged

Kostis-S-Z merged 9 commits into
mainfrom
download-extract

Conversation

@moz-tello-wharton

Copy link
Copy Markdown
Contributor

Extraction was only reachable through load_dataset, which needs the dataset in the schema registry. With extract=True, download_dataset and download_sample also unpack the archive into a directory beside it and return that directory. It is the directory load_dataset extracts to, so the two never unpack the same archive twice. An existing directory is reused unless overwrite_existing=True, which re-downloads and so re-extracts.

_extract_archive now extracts under a temporary name and renames once complete. Before, it created the target directory first, so an interrupted extraction left a directory that the next call took as finished and skipped. load_dataset gets the fix too.

Replacing a sample also removes the directory the old one was extracted into.

The platform serves a dataset's sample from POST /datasets/{id}/sample-download,
which the SDK had no call for. download_sample mirrors download_dataset: same
arguments, resolves a slug to the dataset id, skips the request when the sample
is already on disk, and reports its own download source.

Two differences follow from the endpoint. The sample's filename is only known
from the response, so samples are kept in samples/<dataset id>/ under the
download directory, and a finished file there means no request is made. The
response carries no checksum, so an interrupted sample download starts again
rather than resuming.

The overwrite, resume, download and rename steps move into _run_download_plan,
and response parsing into _build_download_plan, so both downloads share them.
A refused sample request, such as one for a dataset whose terms have not been agreed to, left an empty samples/<dataset id>/ directory behind.
Extraction was only reachable through load_dataset, which needs the dataset
in the schema registry. With extract=True, download_dataset and
download_sample also unpack the archive into a directory beside it and
return that directory. It is the directory load_dataset extracts to, so the
two never unpack the same archive twice. An existing directory is reused
unless overwrite_existing=True, which re-downloads and so re-extracts.

_extract_archive now extracts under a temporary name and renames once
complete. Before, it created the target directory first, so an interrupted
extraction left a directory that the next call took as finished and
skipped. load_dataset gets the fix too.

Replacing a sample also removes the directory the old one was extracted
into.
Base automatically changed from download-sample to main October 19, 2026 12:42
…ive-python into download-extract

# Conflicts:
#	src/datacollective/datasets.py
#	src/datacollective/download.py
#	tests/test_datasets.py
#	tests/test_download.py
@Kostis-S-Z
Kostis-S-Z merged commit 435da50 into main Oct 19, 2026
3 checks passed
@Kostis-S-Z
Kostis-S-Z deleted the download-extract branch October 19, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants